import React, { Component } from 'react'
import zhCN from 'antd/lib/locale-provider/zh_CN';
import enUS from 'antd/lib/locale-provider/en_US';
import enTranslationsData from '../locale/en-US';
import zhTranslationsData from '../locale/zh-CN';
import { LocaleProvider } from 'antd';
import intl from 'react-intl-universal';
import { getLocale, Locale_en_US, Locale_zh_CN } from '../utils/i18n';

require('intl/locale-data/jsonp/en.js');
require('intl/locale-data/jsonp/zh.js');

const AntdTranslations = {
  [Locale_zh_CN]: zhCN,
  [Locale_en_US]: enUS,
}

class BasicLayout extends Component {

  componentDidMount () {
    const currentLocale = getLocale();

    intl.init({
      currentLocale,
      locales: {
        [Locale_zh_CN]: { ...zhTranslationsData },
        [Locale_en_US]: { ...enTranslationsData },
      }
    });
  }

  render () {
    const currentLocale = getLocale();
    return (
      <LocaleProvider locale={AntdTranslations[currentLocale]}>{this.props.children}</LocaleProvider>
    )
  }
}

export default BasicLayout;
